package com.spzx.product.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.spzx.common.core.utils.StringUtils;
import com.spzx.product.domain.Brand;
import com.spzx.product.mapper.BrandMapper;
import com.spzx.product.service.IBrandService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 分类品牌 服务实现类
 * </p>
 *
 * @author atguigu
 * @since 2025-02-19
 */
@Service
public class BrandServiceImpl extends ServiceImpl<BrandMapper, Brand> implements IBrandService {

    @Autowired
    private BrandMapper brandMapper;

    /**
     * 根据品牌名称分页查询品牌列表
     *
     * @param name
     * @return
     */
    @Override
    public List<Brand> findBrandListByPage(String name) {
        //1.创建封装条件Wrapper对象
        LambdaQueryWrapper<Brand> queryWrapper = new LambdaQueryWrapper<>();
        //if (StringUtils.isNotEmpty(name)) {
        //    queryWrapper.like(Brand::getName, name);
        //}
        queryWrapper.like(StringUtils.isNotEmpty(name), Brand::getName, name);
        queryWrapper.select(Brand::getId, Brand::getName, Brand::getLogo, Brand::getCreateTime);
        //2.执行条件查询
        //List<Brand> list = baseMapper.selectList(queryWrapper);
        List<Brand> list = this.list(queryWrapper);

        return list;
    }
}
